﻿$(document).ready(function() {
    ShowHousing(); //加载房源详细信息
});


var checkSubmitFlg = false;

//提交
function submitOk() {

    var usestr = document.getElementById("use").value;
    if (usestr == "请选择") {
        alert("请选择用途！");
        return false;
    }

    var bname1 = document.getElementById("iEstateName").value;
    if (bname1 == "") {
        alert("请输入楼盘名称!");
        return false;
    }
    var bname = LexunJS.GetSelectText("buildName1");
    if (bname == "请选择") {
        alert("请选择栋阁！");
        return false;
    } else {
        if (bname.length = 0 || bname.replace(/(^\s*)|(\s*$)/g, "") == "") {
            alert("请选择栋阁！");
            return false;
        }
    }
    var roomno = document.getElementById("roomNo").value;
    if (roomno == "") {
        alert("请输入房间号！");
        return false;
    }
    var floor = document.getElementById("floor").value;

    //商铺可以录入负数层
    if (usestr == "2") {
        if (/^(\+|-)?\d+($|\.\d+$)/.test(floor)) {

        }
        else {
            alert("请输入正数或者负数！");
            return false;
        }

    } else {
        if (!LexunJS.isValidPositiveInteger(floor)) {
            alert("楼层只能为数字！");
            return false;
        }
    }



    var owner = document.getElementById("owner").value;
    if (owner.length = 0 || owner.replace(/(^\s*)|(\s*$)/g, "") == "") {
        alert("请输入业主名称！");
        return false;
    }

    var ownerTel = document.getElementById("ownerTel").value;
    var linkmanTel = document.getElementById("linkmanTel").value;
    if (ownerTel.length = 0 || ownerTel.replace(/(^\s*)|(\s*$)/g, "") == "") {
        alert("请输入业主电话！");
        return false;
    } else {
        document.getElementById("ownerTel").value = Descript(ownerTel);
        document.getElementById("linkmanTel").value = Descript(linkmanTel);
    }

    var acreage = document.getElementById("acreage").value;
    if (acreage.length = 0 || acreage.replace(/(^\s*)|(\s*$)/g, "") == "") {
        alert("请输入面积！");
        return false;
    }


    var tradeType = document.getElementById("tradeType").value;
    
    if (usestr == "1") {
        var room = LexunJS.GetSelectText("room");
        if (room == "请选择") {
            alert("请选择户型！");
            return false;
        }

        var age = document.getElementById("age").value;
        if (age == "" || age == "0") {
            alert("选输入房龄！");
            return false;
        }
        if (tradeType == "2") {
            var rentNumber = document.getElementById("rentNumber").value;
            if (rentNumber == "") {
                alert("请输入几租！");
                return false;
            }

            var depositNumber = document.getElementById("depositNumber").value;
            if (depositNumber == "") {
                alert("请输入几押！");
                return false;
            }
        }
        var trueArea = document.getElementById("trueArea").value;
        if (trueArea.length = 0 || trueArea.replace(/(^\s*)|(\s*$)/g, "") == "" ||trueArea<=0) {
            alert("请填写使用面积！");
            return false;
        }
    }
    
    

    //判断是否是赎楼 0,代表是
    if (document.getElementById("redeem").checked) {
        document.getElementById("redeem1").value = "1";
    } else {
        document.getElementById("redeem1").value = "0";
    }
    //判断是否有钥匙 0,代表选是
    if (document.getElementById("hasKey").checked) {
        document.getElementById("hasKey1").value = "1";
        var keyno = document.getElementById("keyNo").value;
        if (keyno.length = 0 || keyno.replace(/(^\s*)|(\s*$)/g, "") == "") {
            alert("钥匙编号不能为空！");
            return false;
        }
        var keepKey = document.getElementById("keepKey").value;
        if (keepKey.length = 0 || keepKey.replace(/(^\s*)|(\s*$)/g, "") == "") {
            alert("钥匙人员不能为空！");
            return false;
        }
        var keepKeyDate = document.getElementById("keepKeyDate").value;
        if (keepKeyDate.length = 0 || keepKeyDate.replace(/(^\s*)|(\s*$)/g, "") == "") {
            alert("收钥匙时间不能为空！");
            return false;
        }
    }
    else {
        document.getElementById("hasKey1").value = "0";

    }
    //判断是否是独家 0,代表选中
    if (document.getElementById("isOnly").checked) {
        document.getElementById("isonly1").value = "1";
        var OnlyUser = document.getElementById("OnlyUser").value;
        if (OnlyUser.length = 0 || OnlyUser.replace(/(^\s*)|(\s*$)/g, "") == "") {
            alert("独家人员不能为空！");
            return false;
        }
        var OnlyDate = document.getElementById("OnlyDate").value;
        if (OnlyDate.length = 0 || OnlyDate.replace(/(^\s*)|(\s*$)/g, "") == "") {
            alert("独家时间不能为空！");
            return false;
        }
    }
    else {
        document.getElementById("isonly1").value = "0";
    }
    //判断是否是反签
    if (document.getElementById("ctyCont").checked) {
        document.getElementById("ctyCont1").value = "1";
        var ctyContUser = document.getElementById("ctyContUser").value;
        if (ctyContUser.length = 0 || ctyContUser.replace(/(^\s*)|(\s*$)/g, "") == "") {
            alert("反签人员不能为空！");
            return false;
        }
        var ctyContDate = document.getElementById("ctyContDate").value;
        if (ctyContDate.length = 0 || ctyContDate.replace(/(^\s*)|(\s*$)/g, "") == "") {
            alert("反签时间不能为空！");
            return false;
        }
    }
    else {
        document.getElementById("ctyCont1").value = "0";
    }
    //获取房屋设施选中的值
    var arrInputControls;
    document.getElementById("hAppliances1").value = "";
    arrInputControls = document.getElementsByName("hAppliances");
    var hAppliances = "";
    for (i = 0; i < arrInputControls.length; i++) {
        if (arrInputControls[i].checked == false) {
            hAppliances += "0" + ",";
        }
        else {
            hAppliances += "1" + ",";
        }

    }
    if (hAppliances != "") {
        hAppliances = hAppliances.substr(0, hAppliances.length - 1);
    }
    document.getElementById("hAppliances1").value = hAppliances;

    //ZLHOME 对接，扩展字段
    if (document.getElementById("whetherLease").checked) {
        document.getElementById("whetherLease1").value = 1;
    }

    if (document.getElementById("inLease").checked) {
        document.getElementById("inLease1").value = 1;
    }

    if (document.getElementById("settle").checked) {
        document.getElementById("settle1").value = 1;
    }

    if (document.getElementById("degree").checked) {
        document.getElementById("degree1").value = 1;
    }
    
    
    

    //提交信息
    if (!checkSubmitFlg) {

        // 第一次提交
        checkSubmitFlg = true;
    } else {

        //重复提交
        alert("按一次就够了，请勿重复提交！请耐心等待！谢谢合作！");
        return false;
    }
    //提交信息

    document.forms[0].submit();
}

//加载电话号码
function ShowTel() {
    document.getElementById("ShowTel").style.display = "none";
    document.getElementById("ShowTelId").value = "0";
    var id = LexunJS.GetQueryString("id");
    document.getElementById("hID").value = id;
    $.ajax({
        type: 'POST',
        url: '../Handler/HandlerHousing.ashx',
        data: 'act=SelectHousig&id=' + id,
        timeout: '10000',
        error: function() {
            alert("系统繁忙请稍候后试！");
        },
        success: function(json) {
            showTelCallBack(json);
        }
    });
}
function showTelCallBack(response) {
    var json = eval("(" + response + ")");
    var record = json.record;
    if (record == null || record.length == 0)
        return;
    var recordLength = record.length;

    for (var i = 0; i < recordLength; i++) {
        document.getElementById("ownerTel").value = record[i].ownertel;
        document.getElementById("linkmanTel").value = record[i].linkmantel;

    }
}
//加载房源信息
function ShowHousing() {

    var id = LexunJS.GetQueryString("id");
    document.getElementById("hID").value = id;
    $.ajax({
        type: 'POST',
        url: '../Handler/HandlerHousing.ashx',
        data: 'act=SelectHousig&id=' + id,
        timeout: '10000',
        error: function() {
            alert("系统繁忙请稍候后试！");
        },
        success: function(json) {
            showHousingCallBack(json);
        }
    });
}
function showHousingCallBack(response) {
    var json = eval("(" + response + ")");
    var record = json.record;
    if (record == null || record.length == 0)
        return;
    var recordLength = record.length;

    for (var i = 0; i < recordLength; i++) {

        ///修改盘源时，判断是否是本人
        document.getElementById("owner").value = record[i].owner;


        document.getElementById("iEstateName").disabled = true;
        var userid = document.getElementById("userid").value;
        var deptid = document.getElementById("deptid").value;
        var updateid = document.getElementById("updateId").value; //修改本部客源
        var mid = document.getElementById("mid").value; //修改全部客源
        ///1.如果为资料，并且子状态非：资料转当前待审，垃圾转当前, 并且盘源为有效状态,可以查看业主电话,
        ///2.本人盘源,或者本部，并且角色是经理可以查看业主电话
        ///3.管理
        if ((record[i].status == 2 && record[i].status1 == 0 && record[i].isvalid == 0) || userid == record[i].markuid || (deptid == record[i].markudeptid && updateid == "1") || mid == "1") {
            document.getElementById("divlinkmanTel").style.display = ""; //业主电话
            document.getElementById("divownerTel").style.display = ""; //代理人电话            
        }
        else {
            document.getElementById("floor").disabled = "disabled"; //楼层
            document.getElementById("owner").disabled = "disabled"; //业主
            document.getElementById("linkman").disabled = "disabled"; //联系人
            document.getElementById("divlinkmanTel").style.display = "none"; //业主电话
            document.getElementById("divownerTel").style.display = "none"; //代理人电话
            document.getElementById("source").disabled = "disabled"; //来源
            document.getElementById("propertyRight").disabled = "disabled"; //产权

        }

        var usage = record[i].use;
        if (usage != "1") {
            document.getElementById("floor").readOnly = false;
            document.getElementById("roomNo").readOnly = false;
            document.getElementById("tradeType").disabled = false;
        } else {
            document.getElementById("floor").readOnly = true;
            document.getElementById("roomNo").readOnly = true;
            document.getElementById("tradeType").disabled = true;

        }
        if (usage == "2") {
            document.getElementById("divprice").style.display = "";
            document.getElementById("divzk").style.display = "";
        } else {
            document.getElementById("divprice").style.display = "none";
            document.getElementById("divzk").style.display = "none";


        }
        if (usage != "1" && usage != "4") {
            document.getElementById("divhAppliances").style.display = "none";
            document.getElementById("huxing").style.display = "none";
        }
        var use = document.getElementById("use");

        var buildName1 = document.getElementById("buildName1");
        var buildName2 = document.getElementById("buildName2");
        var buildName3 = document.getElementById("buildName3");

        var useStr = record[i].use;
        LexunJS.selectAddOption(use, LexunJS.GetUsageNameById(useStr), useStr);
        document.getElementById("iEstateName").value = record[i].ename;

        var roleId = $("#RoleId").val();
        if (roleId != "1") {
            if (record[i].buildname1 != "" && typeof (record[i].buildname1) != "undefined" && typeof (record[i].buildname2) != "undefined" && record[i].buildname2 != "" && record[i].bulidname3 != "" && typeof (record[i].bulidname3) != "undefined") {
                LexunJS.selectAddOption(buildName1, record[i].bulidname3, record[i].buildid3);
                LexunJS.selectAddOption(buildName2, record[i].buildname1, record[i].buildid1);
                LexunJS.selectAddOption(buildName3, record[i].buildname2, record[i].buildid2);
            } else if (record[i].buildname1 != "" && typeof (record[i].buildname1) != "undefined" && typeof (record[i].buildname2) != "undefined" && record[i].buildname2 != "") {
                LexunJS.selectAddOption(buildName1, record[i].buildname1, record[i].buildid1);
                LexunJS.selectAddOption(buildName2, record[i].buildname2, record[i].buildid2);
            } else if (record[i].buildname2 != "" && typeof (record[i].buildname2) != "undefined") {
                LexunJS.selectAddOption(buildName1, record[i].buildname2, record[i].buildid2);
            }
        } else {
            $("#level1").val(record[i].level1);
            $("#level2").val(record[i].level2);
            $("#level3").val(record[i].level3);
            loadBuild(record[i].eid, record[i].level1)

            loadparentBuild1();

            loadparentBuild31();

            document.getElementById("iEstateName").disabled = false;

        }



        document.getElementById("bname1").value = record[i].buildname;
        document.getElementById("roomNo").value = record[i].roomno;
        document.getElementById("roomid").value = record[i].roomid;
        document.getElementById("dname1").value = record[i].dname;
        document.getElementById("area1").value = record[i].area;
        var dname = document.getElementById("dname");
        LexunJS.selectAddOption(dname, record[i].dname, record[i].did);
        var area = document.getElementById("area");
        LexunJS.selectAddOption(area, record[i].area, record[i].aid);

        document.getElementById("tenant").value = record[i].tenant; //租客
        document.getElementById("assignmentfee").value = record[i].assignmentfee; //转让费
        document.getElementById("markUId1").value = record[i].markuid; //登盘人ID
        document.getElementById("markUser1").value = record[i].markuser; //登盘人名称
        document.getElementById("markUDeptId1").value = record[i].markudeptid;
        document.getElementById("markUDept1").value = record[i].markudept;
        document.getElementById("addUId1").value = record[i].adduid;
        document.getElementById("addUser1").value = record[i].adduser;
        document.getElementById("addUDept1").value = record[i].addudept;
        document.getElementById("addUDeptId1").value = record[i].addudeptid;
        document.getElementById("addUBankId1").value = record[i].addubank;

        document.getElementById("acreage").value = record[i].acreage;

        var tradeType = document.getElementById("tradeType"); //类型
        tradeType.selectedIndex = record[i].tradetype
        if (tradeType.value == "1") {
            document.getElementById("sprice1").value = "万";
            document.getElementById("sprice").value = "万";
            document.getElementById("divleaseprice").style.display = "none";
            document.getElementById("divleaseYear").style.display = "none";
            document.getElementById("divtotalprice").style.display = "";
        } else {
            document.getElementById("sprice1").value = "元";
            document.getElementById("sprice").value = "元";
            document.getElementById("divleaseYear").style.display = "";
            document.getElementById("divleaseprice").style.display = "";
            document.getElementById("divtotalprice").style.display = "none";
        }







        document.getElementById("linkman").value = record[i].linkman;

        var status = document.getElementById("status"); //状态
        status.selectedIndex = record[i].status;

        document.getElementById("totalprice").value = record[i].totalprice; //总价
        document.getElementById("unitprice").value = record[i].unitprice;
        document.getElementById("costprice").value = record[i].costprice;
        document.getElementById("leaseprice").value = record[i].leaseprice;


        var source = document.getElementById("source");
        LexunJS.selectAddOption(source, record[i].source, record[i].source);

        document.getElementById("pocNo").value = record[i].pocno;

        document.getElementById("houseType").value = record[i].housetype;
        document.getElementById("keyNo").value = record[i].keyno;
        if (record[i].haskey == "1") {//是否有钥匙1.有
            document.getElementById("hasKey").checked = true;
        }
        if (record[i].isonly == "1") {//是否钥匙1.有
            document.getElementById("isOnly").checked = true;
        }
        if (record[i].ctycont == "1") {//反签1.是
            document.getElementById("ctyCont").checked = true;
        }
        if (record[i].redeem == "1") {//赎楼.1是
            document.getElementById("redeem").checked = true;
        }
        document.getElementById("keepKey").value = record[i].keepkey; //钥匙
        document.getElementById("keepKeyDate").value = record[i].keepkeydate;
        document.getElementById("OnlyUser").value = record[i].onlyuser; //独家
        document.getElementById("OnlyDate").value = record[i].onlydate;
        document.getElementById("ctyContUser").value = record[i].ctycontuser; //反签
        document.getElementById("ctyContDate").value = record[i].ctycontdate;
        document.getElementById("remark").value = record[i].remark;
        document.getElementById("isValid").value = record[i].isvalid;
        var room = document.getElementById("room");
        room.selectedIndex = record[i].room;

        var hall = document.getElementById("hall");
        hall.selectedIndex = record[i].hall;
        var restroom = document.getElementById("restroom");
        restroom.selectedIndex = record[i].restroom;
        var kitchen = document.getElementById("kitchen");
        kitchen.selectedIndex = record[i].kitchen;
        var balcony = document.getElementById("balcony");
        balcony.selectedIndex = record[i].balcony;

        var fitment = document.getElementById("fitment");
        fitment.value = record[i].fitment;
        var source = document.getElementById("source"); //来源
        source.value = record[i].source;
        var houseStyle = document.getElementById("houseStyle"); //样式
        houseStyle.value = record[i].housestyle;

        var direct = document.getElementById("direct");
        direct.value = record[i].direct;
        var propertyRight = document.getElementById("propertyRight");
        propertyRight.value = record[i].propertyright;
        var useStatus = document.getElementById("useStatus"); //使用状态
        useStatus.value = record[i].usestatus;
        var pocStatus = document.getElementById("pocStatus"); //房产证状态
        pocStatus.value = record[i].pocstatus;
        var makename = document.getElementById("makename"); //开盘人
        makename.value = record[i].markuser;
        var makedept = document.getElementById("makedept"); //部门
        makedept.value = record[i].markudept;

        var regname = document.getElementById("regname"); //登盘人
        regname.value = record[i].adduser;
        var regdept = document.getElementById("regdept"); //部门
        regdept.value = record[i].addudept;

        document.getElementById("floor").value = record[i].mark1; //楼层
        document.getElementById("leaseYear").value = record[i].mark3; //租期
        document.getElementById("mark2").value = record[i].mark2; //营业税
        var markuid = document.getElementById("markUId1"); //开盘人id
        markuid.value = record[i].markuid;
        var markuid = document.getElementById("markUser1"); //开盘人名称
        markuid.value = record[i].markuser;
        var markuid = document.getElementById("markUDeptId1"); //开盘人部门ID
        markuid.value = record[i].markudeptid;
        var markuid = document.getElementById("markUDept1"); //开盘人部门
        markuid.value = record[i].markudept;
        var markuid = document.getElementById("addUId1"); //登盘人id
        markuid.value = record[i].adduid;
        var markuid = document.getElementById("addUser1"); //登盘人
        markuid.value = record[i].adduser
        var markuid = document.getElementById("addUDept1"); //登盘人部门ID
        markuid.value = record[i].addudept;
        var markuid = document.getElementById("addUDeptId1"); //登盘人部门
        markuid.value = record[i].addudeptid


        document.getElementById("age").value = record[i].age; //房龄
        document.getElementById("rentNumber").value = record[i].rentnumber; //房龄
        document.getElementById("depositNumber").value = record[i].depositnumber; //房龄
        document.getElementById("trueArea").value = record[i].truearea;//使用面积



        if (record[i].whetherlease == "True")
            document.getElementById("whetherLease").checked = true;

        if (record[i].inlease == "True")
          document.getElementById("inLease").checked =true;

      
        if (record[i].settle == "True")
            document.getElementById("settle").checked = true;

        if (record[i].degree == "True")
              document.getElementById("degree").checked = true;
      



        ///遍历房屋设施;
        if (usage == "1") {
            var list = record[i].happliances;
            if (list == null) {
                return;
            }
            var arr = new Array();
            arr = list.split(',');

            for (var i = 0; i < arr.length; i++) {
                var arrInputControls;
                arrInputControls = document.getElementsByName("hAppliances");
                if (arr[i] == "1") {
                    arrInputControls[i].checked = true;
                }
                else if (arr[i] == "0") {
                    arrInputControls[i].checked = false;
                }

            }
        }



    }

}
function isValidPositiveInteger(obj) {

    if (!LexunJS.isValidPositiveInteger(obj.value)) {

        alert("输入有误，只能为整数！");
        obj.value = "";
        return false;
    }
}

//checkbox全选反选
function SelectAll() {
    var arrInputControls;
    arrInputControls = document.getElementsByName("hAppliances");
    if (arrInputControls == null) {
        return;
    }

    for (i = 0; i < arrInputControls.length; i++) {
        if (arrInputControls[i].checked == false) {
            arrInputControls[i].checked = true;
        }
        else {
            arrInputControls[i].checked = false;
        }

    }
}
// 级联加载列表
function loadBuild(id, buildid) {
    $.ajax({
        type: 'POST',
        url: '../Handler/HandlerIndex.ashx',
        data: 'act=SelectNamesById&id=' + id,
        timeout: '10000',
        error: function() {
            alert("编缉失败！");
        }, success: function(json) {
            loadBuildCallBack(json, buildid);
        }
    });
}

// 加载城市列表回调
function loadBuildCallBack(response, buildid) {
    var json = eval("(" + response + ")");
    var record = json.record;
    $("#buildName1").html("");
    $("#bid1").html("");

    var obj = document.getElementById("buildName1");
    LexunJS.selectAddOption(obj, "请选择", 0);
    if (record == null || record.length == 0)
        return;
    var recordLength = record.length;
    for (var i = 0; i < recordLength; i++) {
        var sName = record[i].name;
        var sValue = record[i].id;
        LexunJS.selectAddOption(obj, sName, sValue);
    }

    for (var j = 0; j < obj.length; j++) {

        if (obj[j].value == buildid) {
            document.getElementById("bid1").value = buildid;
            setTimeout(function() { obj.options[j].selected = true; });

            break;
        }
    }


}
//加载栋阁
function loadparentBuild() {

    var id = LexunJS.GetSelectValue("buildName1");

    document.getElementById("bid1").value = id; //栋阁id，名称

    document.getElementById("bname1").value = LexunJS.GetSelectText("buildName1");

    $.ajax({
        type: 'POST',
        url: '../Handler/HandlerIndex.ashx',
        data: 'act=SelectNamesByBId&id=' + id,
        timeout: '10000',
        error: function() {
            alert("系统繁忙，请稍候后试！");
        }, success: function(json) {
            SelectNameByParent(json);
        }
    });
}

//修改盘源加载栋阁
function loadparentBuild1() {

    var id = document.getElementById("level1").value;

    $.ajax({
        type: 'POST',
        url: '../Handler/HandlerIndex.ashx',
        data: 'act=SelectNamesByBId&id=' + id,
        timeout: '50000',
        error: function() {
            alert("系统繁忙，请稍候后试！");
        }, success: function(json) {
            SelectNameByParent(json);
        }
    });
}


// 加载城市列表回调
function SelectNameByParent(response) {
    var json = eval("(" + response + ")");
    var record = json.record;

    $("#buildName2").html("");
    var obj = document.getElementById("buildName2");
    LexunJS.selectAddOption(obj, "全部", 0);
    if (record == null || record.length == 0)
        return;

    var recordLength = record.length;
    for (var i = 0; i < recordLength; i++) {
        var sName = record[i].name;
        var sValue = record[i].id;
        LexunJS.selectAddOption(obj, sName, sValue);

    }


    var level2 = document.getElementById("level2").value;

    for (var j = 0; j < obj.length; j++) {

        if (obj[j].value == level2) {
            document.getElementById("bid2").value = level2;

            setTimeout(function() { obj.options[j].selected = true; });

            break;
        }
    }



}

//加载栋阁
function loadparentBuild3() {
    var id = LexunJS.GetSelectValue("buildName2");

    document.getElementById("bid2").value = id; //栋阁id，名称

    document.getElementById("bname2").value = LexunJS.GetSelectText("buildName2");

    $.ajax({
        type: 'POST',
        url: '../Handler/HandlerIndex.ashx',
        data: 'act=SelectNamesByBId&id=' + id,
        timeout: '10000',
        error: function() {
            alert("系统繁忙，请稍候后试！");
        }, success: function(json) {
            SelectNameByParent3(json);
        }
    });
}

function loadparentBuild31() {
    var id = document.getElementById("level2").value;

    $.ajax({
        type: 'POST',
        url: '../Handler/HandlerIndex.ashx',
        data: 'act=SelectNamesByBId&id=' + id,
        timeout: '50000',
        error: function() {
            alert("系统繁忙，请稍候后试！");
        }, success: function(json) {
            SelectNameByParent3(json);
        }
    });
}



// 加载城市列表回调
function SelectNameByParent3(response) {
    var json = eval("(" + response + ")");
    var record = json.record;

    $("#buildName3").html("");
    var obj = document.getElementById("buildName3");

    LexunJS.selectAddOption(obj, "全部", 0);

    if (record == null || record.length == 0)
        return;

    var recordLength = record.length;
    for (var i = 0; i < recordLength; i++) {
        var sName = record[i].name;
        var sValue = record[i].id;

        LexunJS.selectAddOption(obj, sName, sValue);
    }

    var level3 = document.getElementById("level3").value;


    for (var j = 0; j < obj.length; j++) {

        if (obj[j].value == level3) {
            document.getElementById("bid3").value = level3;

            setTimeout(function() { obj.options[j].selected = true; });

            break;
        }
    }


}
//取栋阁
function loadparentBuildName() {
    document.getElementById("bid3").value = LexunJS.GetSelectValue("buildName3"); //栋阁id，名称
    document.getElementById("bname3").value = LexunJS.GetSelectText("buildName3");

}

function clearValue() {
    document.getElementById("roomNo").value = "";
    document.getElementById("floor").value = "";
    document.getElementById("roomid").value = "";
    document.getElementById("divBackRm").style.display = "";

}


function DisplyDiv() {
    var usage = LexunJS.GetSelectText("use");
    if (usage == "2") {
        document.getElementById("divprice").style.display = "";
        document.getElementById("divzk").style.display = "";
    } else {
        document.getElementById("divprice").style.display = "none";
        document.getElementById("divzk").style.display = "none";

    }
}


//验证电话号码以及手机号码
function chkForm(txtOTel) {
    var p1 = /^((1[0-9]{1}[0-9]{1})+\d{8})|(^(0[0-9]{2,3}\-)?([2-9][0-9]{6,7})+(\-[0-9]{1,4})?$)|(^([0-9]{3,5}\-)?([0-9]{3,9})?(\-[0-9]{3,9}))$/;

    if (txtOTel.value.substr(0, 1) == "1") {
        if (txtOTel.value.length != "11") {
            alert("号码格式不正确，请检查输入的电话号码");
            txtOTel.value = "";
            return false;
        }
    }

    if (p1.test(txtOTel.value) == false && txtOTel.value != "") {
        alert("号码格式不正确，请检查输入的电话号码");
        txtOTel.value = "";

        return false;

    }


}

//计算总价
function ComputerTotal() {
    var acreage = document.getElementById("acreage").value;
    var unitprice = document.getElementById("unitprice").value;
    var totalpric = document.getElementById("totalprice");
    var tardetype = document.getElementById("tradeType").value;
    if (tardetype == "1")
        totalpric.value = parseFloat(acreage * unitprice / 10000).toFixed(2);
    else
        totalpric.value = parseFloat(acreage * unitprice).toFixed(2);
}

function Computer() {
    var totalpric = document.getElementById("totalprice").value;
    var acreage = document.getElementById("acreage").value;
    var unitprice = document.getElementById("unitprice");
    var leaseprice = document.getElementById("leaseprice").value;
    if ((totalpric != "" && acreage != "") || (leaseprice != "" && acreage != "")) {

        var tradeType = document.getElementById("tradeType").value;
        if (tradeType == 1) {
            var sprice1 = document.getElementById("sprice").value;
            if (sprice1 == "万") {
                unitprice.value = parseFloat(totalpric * 10000 / acreage).toFixed(2);
            } else {
                unitprice.value = parseFloat(totalpric / acreage).toFixed(2);
            }
        } else {
            var RentPrice = document.getElementById("RentPrice").value;
            if (RentPrice == "元/月") {
                unitprice.value = parseFloat(leaseprice / acreage).toFixed(2);
            } else {
                unitprice.value = parseFloat(leaseprice / acreage * 10000).toFixed(2);
            }
        }
    }
    else {
        unitprice.value = "";
    }
}
//价格单位改变的时候，重新计算单价
function ComputerPrice() {
    var sprice1 = document.getElementById("sprice").value; //价格单位
    var totalpric = document.getElementById("totalprice").value;
    var acreage = document.getElementById("acreage").value;
    var unitprice = document.getElementById("unitprice");
    if (totalpric != "" && acreage != "") {
        if (sprice1 == "万") {
            unitprice.value = parseFloat(totalpric * 10000 / acreage).toFixed(2); //出售，单价
        } else {
            unitprice.value = parseFloat(totalpric / acreage).toFixed(2); //出租,单价
        }
    }
}
//价格单位改变的时候，重新计算单价

function CRentPrice() {
    var RentPrice = document.getElementById("RentPrice").value;
    var acreage = document.getElementById("acreage").value;
    var unitprice = document.getElementById("unitprice");
    var leaseprice = document.getElementById("leaseprice").value;
    if (leaseprice != "" && acreage != "") {
        if (RentPrice == "元/月") {
            unitprice.value = parseFloat(leaseprice / acreage).toFixed(2);
        } else {
            unitprice.value = parseFloat(leaseprice / acreage * 10000).toFixed(2);
        }
    }
}


//转换电话号码
function Enscript(strTel) {
    var str = "";
    for (var i = 0; i < strTel.length; i++) {
        var sTel = strTel.substr(i, 1);
        switch (sTel) {
            case "0":
                str += "J";
                break;
            case "1":
                str += "A";
                break;
            case "2":
                str += "B";
                break;
            case "3":
                str += "C";
                break;
            case "4":
                str += "D";
                break;
            case "5":
                str += "E";
                break;
            case "6":
                str += "F";
                break;
            case "7":
                str += "G";
                break;
            case "8":
                str += "H";
                break;
            case "9":
                str += "I";
                break;
            default:
                str += sTel;
                break;
        }
    }
    return str;
}
function Descript(strTel) {
    var str = "";
    for (var i = 0; i < strTel.length; i++) {
        var sTel = strTel.substr(i, 1);
        switch (sTel) {
            case "J":
                str += "0";
                break;
            case "A":
                str += "1";
                break;
            case "B":
                str += "2";
                break;
            case "C":
                str += "3";
                break;
            case "D":
                str += "4";
                break;
            case "E":
                str += "5";
                break;
            case "F":
                str += "6";
                break;
            case "G":
                str += "7";
                break;
            case "H":
                str += "8";
                break;
            case "I":
                str += "9";
                break;
            default:
                str += sTel;
                break;
        }
    }
    return str;
}

function ClearText1() {
    document.getElementById("OnlyUser").value = "";
    document.getElementById("OnlyDate").value = "";
}
function ClearText2() {
    document.getElementById("keyNo").value = "";
    document.getElementById("keepKey").value = "";
    document.getElementById("keepKeyDate").value = "";

}
function ClearText3() {
    document.getElementById("ctyContUser").value = "";
    document.getElementById("ctyContDate").value = "";
}
//返回
function ReBack() {
    var url = "../PM/HousingManager.aspx?typeid=0";
    self.parent.closeTab('修改盘源');
    self.parent.addTab('盘源列表', url, 'icon-nav');
}
//弹出窗口,取返回值
function roomNoDialog() {
    var ename = document.getElementById("iEstateName").value;
    var bname2 = document.getElementById("bname2").value;
    var bname3 = document.getElementById("bname3").value;
    var id = document.getElementById("buildName1").value;
    if (bname2.length > 0) {
        id = document.getElementById("buildName2").value;
    }
    if (bname3.length > 0) {
        id = document.getElementById("buildName3").value;

    }

    if (id == 0 || id == "") {
        alert("请选择栋阁！");
        return;
    }

    //弹出房号列表
    var path = "../TM/ShowRooms.aspx?id=" + id;
    var parameter = "";
    var style = "dialogWidth:638px; dialogHeight:563px; status:0;scroll:1; help:0; resizable:1;Scrollbars=yes,Toolbar=no,Location=no,Direction=no,Resizeable=no";
    var arr = window.showModalDialog(path, parameter, style);

    if (typeof (arr) == "undefined" || arr == null) {

        return;
    }
    var str = new Array();
    str = arr.split(',');
    document.getElementById("roomNo").value = ""; // 清空房号，ID
    document.getElementById("roomid").value = "";
    document.getElementById("floor").value = "";


    document.getElementById("roomNo").value = str[0];
    document.getElementById("roomid").value = str[1];
    document.getElementById("floor").value = str[2];

}